import requests
from lxml import etree


url = 'https://www.guangshan.gov.cn/xwzx/gsyw/'

r = requests.get(url)
# print(r.content.decode('utf-8'))

tree = etree.HTML(r.content.decode('utf-8'))
msg_urls = tree.xpath('//ul[@class="newsList"]/li/a/@href')


for msg_url in msg_urls:
    print(msg_url)
    detail_url = requests.get(msg_url)
    detail_tree = etree.HTML(detail_url.content.decode('utf-8'))
    detail_title = detail_tree.xpath('//div[@class="detailBox"]/div[@class="title"]/text()')
    detail_msgs = detail_tree.xpath('//div[@class="detailBox"]/div[@id="content"][1]/p/text()')
    detail_msgs = [item.replace('\u3000', '') for item in detail_msgs]
    print(detail_title)
    print(detail_msgs)

